package com.zhong.gang.applib.ui.preview;

import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.util.Log;
import android.view.View;

import androidx.fragment.app.Fragment;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.DecodeFormat;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.request.RequestOptions;
import com.bumptech.glide.request.target.SimpleTarget;
import com.bumptech.glide.request.transition.Transition;
import com.zhong.gang.applib.R;
import com.zhong.gang.applib.base.fm.FmBase;
import com.zhong.gang.applib.databinding.FmPerviewBinding;
import com.zhong.gang.applib.utils.GlideUtils;

import java.util.List;

public class PerviewFragment extends FmBase<FmPerviewBinding> {
    private static final String DATA="DATA",NUMBER = "NUMBER",COUNT ="COUNT";
    public static final PerviewFragment newIntent(String list,int number,int count){
        Bundle bundle = new Bundle();
        PerviewFragment fragment = new PerviewFragment();
        bundle.putString(DATA,list);
        bundle.putInt(NUMBER,number);
        bundle.putInt(COUNT,count);
        fragment.setArguments(bundle);
        return fragment;
    }
    @Override
    public int LayoutRes() {
        return R.layout.fm_perview;
    }

    @Override
    public void getData() {

    }

    @Override
    public void initView() {
        if (GlideUtils.isContextExisted(getContext())){
            Glide.with(getContentView())
                    .load(getArguments().getString(DATA))
                    .apply(new RequestOptions()
                            .frame(1000)
                            .dontAnimate()
                            .format(DecodeFormat.PREFER_RGB_565)
                            .diskCacheStrategy(DiskCacheStrategy.ALL))
                    .thumbnail( 0.5f )
                    .into(bind.image);
        }
        bind.num.setText(getArguments().getInt(NUMBER)+"/"+getArguments().getInt(COUNT));

        bind.image.enable();
        bind.image.enableRotate();
        bind.image.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                getActivity().finish();
            }
        });
    }

    @Override
    public boolean showLoading() {
        return false;
    }
}
